#include "dateedit.h"
#include <QDebug>


DateEdit::DateEdit(QWidget *parent) :
    QDateEdit(parent)
{
    calendar.setWindowFlags(Qt::Popup);
    connect(&calendar,SIGNAL(clicked(QDate)),this,SLOT(onCalendarClicked(QDate)));
    setDate(QDate::currentDate());
}

void DateEdit::contextMenuEvent(QContextMenuEvent* event)
{
    if(isReadOnly()) return;
    calendar.setGeometry(event->globalPos().x(),event->globalPos().y(),200,200);
    calendar.show();
    calendar.setCurrentPage(date().year(),date().month());
    calendar.setSelectedDate(date());
    event->accept();
}

void DateEdit::onCalendarClicked(const QDate&date)
{
    setDate(date);
    calendar.hide();
}


